﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OfficeClip.OpenSource.SpellO
{
	public partial class AddNew : Form
	{
		public Form1 parentForm;
		public AddNew()
		{
			InitializeComponent();
		}

		public AddNew(Form1 frm1)
			: this()
		{
			parentForm = frm1;
		}

		private void button2_Click(object sender, EventArgs e)
		{
			// first check if the id is already there, if so, give an error!
			foreach (Settings.Site ste in parentForm.spello.Sites)
			{
				if (txtNewSite.Text.Trim() == ste.Id)
				{
					MessageBox.Show(
                        "The Site Id already exists",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1
                        );
					return;
				}
			}
			Settings.Site site = new OfficeClip.OpenSource.SpellO.Settings.Site();
			site.Crawler = new OfficeClip.OpenSource.SpellO.Settings.Crawler();
            site.Crawler.DisallowedUrls = new List<string>();
            site.Crawler.DisallowedUrls.Add(@"(\.jpg|\.css|\.js|\.gif|\.jpeg|\.png)");

			site.SpellCheck = new OfficeClip.OpenSource.SpellO.Settings.SpellCheck();
			site.SpellCheck.AllowWords = new List<string>();
			site.Id = txtNewSite.Text.Trim();
			parentForm.spello.Sites.Add(site);
			Constants.Serialize(parentForm.spello);
			parentForm.PopulateCombo();
			this.Close();
		}

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
	}
}
